#include <stdio.h>
#include <string.h>
#include "cautil.h"



char *krstrtoken(char *dest, char *buf, char *delstr, char *delc, int *datalen, int destlen)
{
	char *ptr = buf;
	int cnt=0;
	char c=0;
	*datalen = 0;

	for(;;)
	{
		c = *ptr++;
		//if(c == del)
		if(!c)
		{
			if(delc) *delc = c;
			dest[cnt] = 0;
			return NULL;
		}
		else if(strchr(delstr,c))
		{
			if(cnt)
			{
				if(delc) *delc = c;
				dest[cnt] = 0;
				if(*ptr)
				{
					*datalen = cnt;
					return ptr;
				}
				else return NULL;
			}
		}
		
		else
		{
			if(cnt<destlen)
			{
				dest[cnt++] = c;
			}
		}
	}

	return NULL;
}


